package com.yao.club.controller.goods;

import com.yao.club.entity.dto.GoodsFootPrintRecord;
import com.yao.club.entity.result.ResponseEntity;
import com.yao.club.entity.result.ResultEntity;
import com.yao.club.service.GoodsFootPrintService;
import com.yao.club.token.UserToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;

@Api(tags = "俱乐部商城-商品浏览足迹")
@RestController
@RequestMapping("/mall/goodsFootPrint")
public class GoodsFootPrintController {

    @Autowired
    private GoodsFootPrintService goodsFootPrintService;
    @Resource
    HttpServletRequest request;



    @UserToken
    @ApiOperation(value = "添加足迹")
    @PostMapping("/add/{goodsId}")
    @ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, dataType = "Long", paramType = "path")
    public ResponseEntity<Boolean> addFootPrint(
            @PathVariable Long goodsId) {
        String username = (String) request.getAttribute("username");
        return goodsFootPrintService.addFootPrint(goodsId, username);
    }

    @UserToken
    @ApiOperation(value = "查看自己的足迹")
    @GetMapping("/view")
    public ResponseEntity<ResultEntity<GoodsFootPrintRecord>> viewFootPrints() {
        String username = (String) request.getAttribute("username");
        return goodsFootPrintService.getFootPrints(username);
    }
} 